package com.sunni.mapper;

import com.sunni.entity.Employee;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface EmployeeMapper {

    @Insert("insert into `sys_employee` values(#{id},#{name})")
    void save(Employee employee);

    @Delete("delete from `sys_employee` where id=#{id}")
    void delete(Integer id);

    @Update("update `sys_employee` set name=#{name} where id=#{id}")
    void update(Employee employee);

    @Select("select * from `sys_employee` where id=#{id}")
    Employee selectById(Integer id);

    @Select("select * from `sys_employee`")
    List<Employee> selectAll();

    /*day16-07: 多对多  查询employee（包含roleList属性）*/
    @Select("select * from sys_employee")
    @Results({
            @Result(id = true, property = "id", column = "id"),
            @Result(property = "name",column = "name"),
            @Result(
                    javaType = List.class,
                    property = "roleList",
                    column = "id", /*vvvvvvvvvvvv id作为参数  传给另一个方法 （封装roleList）*/
                    many = @Many(select = "com.sunni.mapper.RoleMapper.selectByEmployeeId") /*调用另一个方法 封装roleList*/
            )
    })
    List<Employee> selectEmployeeAllAndRoleList();
}
